package com.ilovepostcard.view;

import com.ilovepostcard.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RadioView extends LinearLayout {

    ImageView iamge;
    private String text;
    boolean checked;

    public RadioView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PostcardRadiobox);
        checked = ta.getBoolean(R.styleable.PostcardRadiobox_checked, false);
        text = ta.getString(R.styleable.PostcardRadiobox_radio_text);
        inflate();
    }

    public RadioView(Context context) {
        super(context);
        inflate();
    }

    public boolean isChecked() {
        return checked;
    }
    
    public void setChecked(boolean b) {
        checked = b;
        iamge.setImageResource(checked ? R.drawable.radiobox_check : 0);
    }
    
    private void inflate() {
        View view = View.inflate(getContext(), R.layout.radio_box, this);
        iamge = (ImageView) view.findViewById(R.id.radio_image);
        iamge.setImageResource(checked ? R.drawable.radiobox_check : 0);
//        view.setOnClickListener(new View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                checked = !checked;
//                iamge.setImageResource(checked ? R.drawable.radiobox_check : 0);
//            }
//        });
        TextView textView = (TextView) view.findViewById(R.id.radio_text);
        textView.setText(text);
    }
}
